package cn.wolfcode.wms.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Product extends BaseDomain {
    //商品名称
    private String name;
    //商品编号
    private String sn;
    //成本价
    private BigDecimal costPrice;
    //市场价
    private BigDecimal salePrice;
    //商品图片
    private String imagePath;
    //商品介绍
    private String intro;
    //关联的品牌
    private Long brandId;
    //品牌名称
    private String brandName;


    public String getJson(){
        Map<String ,Object> json = new HashMap<>();
        json.put("id",getId());
        json.put("name",name);
        json.put("costPrice",costPrice);
        json.put("salePrice",salePrice);
        json.put("brandName",brandName);
        return JSON.toJSONString(json);
    }





    // <td><img src="${c.smallImagePath}"  class="list_img_min"/></td>
   public String getSmallImagePath(){

       if(StringUtils.isEmpty(imagePath)){
           return ":";
       }
       return  this.imagePath.substring(0,this.imagePath.lastIndexOf("."))+"_small" +this.imagePath.substring(this.imagePath.lastIndexOf("."));
    }


}